package dialogs;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import controllers.AbstractController;

@SuppressWarnings("serial")
public class InsertTupleDialog extends AbstractGeneralPurposeDialog {
	public InsertTupleDialog(JFrame parent, String title, String table,
			String[] labels, AbstractController c) {
		super(parent, title, table, labels, c);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		String actionCommand = e.getActionCommand();
		Vector<String> s = new Vector<String>();
		for (JTextField j : text_fields)
			s.add(j.getText());

		if (actionCommand.equals("OK"))
			if (controller.validateInsert(s) != VALIDATIONERROR) {
				dispose();
				controller.show();
			} else {
				Toolkit.getDefaultToolkit().beep();

				// display a popup to inform the user of the validation error
				JOptionPane.showMessageDialog(this, "Invalid Input", "Error",
						JOptionPane.ERROR_MESSAGE);
			}
	}
}
